package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;

import flc.ast.AppConfig;
import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.HotAdapter;
import flc.ast.adapter.MovieListAdapter;
import flc.ast.databinding.ActivityMovieListBinding;
import stark.common.api.StkResApi;
import stark.common.base.IReqRetCallback;
import stark.common.basic.event.EventStatProxy;
import stark.common.bean.StkResBean;
import stark.common.bean.StkTagResBean;

public class MovieListActivity extends BaseAc<ActivityMovieListBinding> {

    protected MovieListAdapter movieAdapter;
    private int page = 1;
    private int refreshTime = 200;

    @Override
    protected int onCreate() {
        return R.layout.activity_movie_list;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivMovieListBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.rvMovieList.setLayoutManager(new LinearLayoutManager(mContext));
        movieAdapter = new MovieListAdapter();
        mDataBinding.rvMovieList.setAdapter(movieAdapter);
        movieAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        ListDetailActivity.stkTagResBean = movieAdapter.getItem(position);
        startActivity(ListDetailActivity.class);
    }

    @Override
    protected void initData() {
        getData();
    }

    private void getData() {
        StkResApi.getChildTagList(this, AppConfig.MOVIE_LIST_DATA, StkResApi.createParamMap(0, 12), false, new IReqRetCallback<List<StkTagResBean>>() {
            @Override
            public void onResult(boolean success, String msg, @Nullable List<StkTagResBean> result) {
                if (success) {
                    if (result != null && result.size() > 0) {
                        movieAdapter.setList(result);
                    }
                }
            }
        });
    }

}